﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Basic_sprite_code
{
    class Fire:Sprite
    {
        public int evilnessLevel;
        public int firePower;
        public int counter;

        public Texture2D pic1;
        public Texture2D pic2;

        public bool isPic1;

        public Fire(DarkLordsApprentice g, Vector2 position, int eLevel, int fPower)
            : base(g, "RedFire1", position, new Vector2(50, 100))
        {
            evilnessLevel = eLevel;
            firePower = eLevel * 10 + fPower;
            counter = 0;

            if (evilnessLevel < 4) {
                pic1 = game.Content.Load<Texture2D>("RedFire1");
                pic2 = game.Content.Load<Texture2D>("RedFire2");
            }
            else if (evilnessLevel < 7) {
                pic1 = game.Content.Load<Texture2D>("BlueFire1");
                pic2 = game.Content.Load<Texture2D>("BlueFire2");
            }
            else {
                pic1 = game.Content.Load<Texture2D>("BlackFire1");
                pic2 = game.Content.Load<Texture2D>("BlackFire2");
            }

            isPic1 = true;

            image = pic1;
            scale = .01f;
        }

        public override void Update(GameTime gameTime)
        {
            if (scale <= 0) {
                game.Components.Remove(this);
            }

            if (counter % 10 == 0)
            {
                if (isPic1)
                {
                    image = pic2;
                    isPic1 = false;
                }
                else
                {
                    image = pic1;
                    isPic1 = true;
                }
            }

            if (position.Y > 500)
            {
                if (counter < 10)
                {
                    scale += (1 + firePower / 100.0f) / 15.0f;
                }
                else if (scale > 0)
                {
                    scale -= .008f;
                }
            }
            else
            {

                float posScale = ((position.Y - 150.0f) / 300);

                if (counter < 10)
                {
                    scale += ((1 + firePower / 100.0f) / 10.0f) * posScale;
                }
                else if (scale > 0)
                {
                    scale -= .008f * posScale;
                }
            }

            counter++;
            
            base.Update(gameTime);
        }
    }
}
